<?php

namespace app\common\service\order\coupon_order\mobile;

use app\common\service\order\coupon_order\Base;
use app\common\service\order\coupon_order\CouponOrderChannelInterface;
use app\model\AgentBalanceLog;
use app\model\CouponOrder;
use app\model\MobileOrder;
use app\model\MobileSupplier;

class MobileSyncBase extends Base implements CouponOrderChannelInterface
{


    public function getMobile()
    {
        return $this->params['mobile'];
    }


    public function getSalesmanId()
    {
        return $this->params['salesman_id'];
    }


    public function getCnid()
    {
        return $this->params['channel_id'];
    }


    public function getSettledAt()
    {
        if ($this->agent_settle_status == CouponOrder::C_AGENT_SETTLE_STATUS_SUCCESS) {
//            agent_balance_log
            /** @var AgentBalanceLog $agentBalanceLog */
            $agentBalanceLog = AgentBalanceLog::query()
                ->where('quote_id', $this->params['id'])
                ->where('trade_no', $this->params['sub_order_id'])
                ->where('agent_id', $this->agent_id)
                ->find();
            if ($agentBalanceLog) {
                return $agentBalanceLog->created_at;
            }

        }
    }

    public function getUserId()
    {
        return $this->params['user_id'];
    }


    public function getAgentId()
    {
        return $this->params['agent_id'];
    }

    public function getSupplierPrice()
    {
        return $this->params['supplier_price'];
    }

    public function getAgentSettleDiscount()
    {
        return $this->params['settle_discount'];
    }

    public function getSettlePrice()
    {
        return $this->params['settle_price'];
    }

    public function getOrderId()
    {
        return $this->params['order_id'];
    }

    public function getSupplierId()
    {
        return $this->params['mobile_supplier_id'];
    }

    public function getSupplierCode()
    {
        return 0;
    }


    public function getSupplierOrderSn()
    {
        return $this->order_id;
    }

    public function getAmount()
    {
        return $this->params['amount'];
    }

    public function getOrderAllCommission()
    {
        return $this->params['profit'];
    }

    public function getOriginAmount()
    {
        return $this->params['sale_price'];
    }

    public function getPayAmount()
    {
        return $this->params['amount'];
    }

    public function getPayStatus()
    {
        $status = $this->params['status'];

        if (in_array($status, [MobileOrder::C_STATUS_HAVE])) {  // '状态：1未支付 2已支付 3已取消 4支付失败',
            return CouponOrder::C_PAY_STATUS_YES;
        } else {
            return CouponOrder::C_PAY_STATUS_NO;
        }
    }

    public function getPayTime()
    {
        return $this->params['created_at'];
    }

    public function getStatusDesc()
    {

    }

    public function getType()
    {
        return 0;
    }

    public function getSettleType()
    {

        return $this->params['settle_type'];

    }

    public function getExtData()
    {
        return $this->params;
    }

    public function getOrderCreatedAt()
    {
        return $this->pay_time;
    }

    public function getTitle()
    {
        return '话费';
    }

    public function getRefundStatus()
    {
        return $this->params['refund_status'];
    }

    public function getSid()
    {
        return '';
    }

    public function getOutOrderId()
    {
        return $this->params['official_sn'];
    }

    public function getPlatformProfit()
    {
        return $this->params['platform_profit'];
    }

    public function getQuoteId()
    {
        return $this->params['id'];
    }

    public function getAccount()
    {
        return $this->mobile;
    }
}